<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /* 1、通过splice去重 es5最常用*/
        var arr = [1,3243,3243,241,12413,3123,123,11,1,1,241]
        for(var i =0;i < arr.length-1 ;i++){
            for(var j = i+1; j < arr.length ;j++){
                if(arr[i]===arr[j]){
                    arr.splice(j,1);
                    j--
                }
            }
        }
        console.log(arr);
        /* 2、通过对象中属性值唯一进行判断  有问题不推荐使用*/
        var arr2 = [1,3243,3243,241,12413,3123,123,11,1,1,241]
        var arr1 = [];
        var obj = {};
        for(var i =0;i < arr2.length;i++){
            if(obj[arr2[i]] === undefined){
                obj[arr2[i]] = 1;
                arr1.push(arr2[i]);
            }
        }
        console.log(arr1);
        /* 3、通过es6新增的set函数进行去重，不支持ie8以下。 es6最常用*/
        var arr3 = [1,3243,3243,241,12413,3123,123,11,1,1,241,{},{},'true','false','true']
        var arr4 = Array.from(new Set(arr3));
        console.log(arr4);
        /* 4、利用indexOf去重 不能够去掉{} 和Nan*/
        var arr5 = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
        var arr6 = [];
        for(var i= 0 ;i < arr5.length;i++){
            if(arr6.indexOf(arr5[i]) === -1){
                arr6.push(arr5[i]);
            }
        }
        console.log(arr6);
        /* 5、 利用sort进行去重*/
        var arr7 = [1,3243,3243,241,12413,3123,123,11,1,1,241];
        arr7.sort();
        var arr8 = [arr7[0]];
        for(var i = 1; i < arr7.length ;i++){
            if(arr7[i]!== arr7[i-1]){
                arr8.push(arr7[i]);
            }
        }
        console.log(arr8);
    </script>
</head>
<body>
    
</body>
</html>